//
//  GWButton.m
//  Glowalker
//
//  Created by 王华磊 on 2017/10/4.
//  Copyright © 2017年 Haley. All rights reserved.
//

#import "GWButton.h"

@implementation GWButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews
{
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    _iconImageView.contentMode = UIViewContentModeScaleToFill;
    [self addSubview:_iconImageView];
    
    _textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _textLabel.textColor = [UIColor whiteColor];
    _textLabel.font = [UIFont systemFontOfSize:15.0];
    _textLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_textLabel];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    
    CGRect bounds = self.bounds;
    _textLabel.frame = CGRectMake(0, bounds.size.height - 20, bounds.size.width, 20);
    
    CGFloat imgH = bounds.size.height - 20;
    if (imgH > 70) {
        imgH = 70;
    }
    
    _iconImageView.frame = CGRectMake((bounds.size.width - imgH) * 0.5, bounds.size.height - 20 - imgH, imgH, imgH);
}

@end
